/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package mapWriters;

import java.io.DataOutputStream;
import java.io.IOException;

import map.file.FileMap;

import figures.Figure;
import figures.basic.ImageFigure;
import figures.basic.PoliLine;
import figures.images.WebIcon;

public class Unloader {

	public static void unload(DataOutputStream os, Figure f) throws IOException {
		os.writeByte(f.getType());
		if(f instanceof PoliLine)
			unloadPoliline(os, (PoliLine)f);
		if(f instanceof ImageFigure)
			if(f instanceof WebIcon)
				unloadWebIcon(os, (WebIcon)f);
			else
				unloadImageFigure(os, (ImageFigure) f);
			
	}
	
	public static void unloadPoliline(DataOutputStream os, PoliLine f) throws IOException {
		os.writeInt(f.namepos);
		os.writeInt(f.ix);
		os.writeInt(f.iy);
		os.writeInt(f.offsetinit<<16|f.l);
	}
	
	public static void unloadImageFigure(DataOutputStream os, ImageFigure f) throws IOException {
		FileMap.writeString(os, new String(f.n));
		os.writeInt(f.xcenter());
		os.writeInt(f.ycenter());
	}
	public static void unloadWebIcon(DataOutputStream os, WebIcon f) throws IOException {
		unloadImageFigure(os, f);
		os.writeInt(f.n);
	}
	
}
